#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mems(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=1000010;
const int inf=1e18;
static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline int read(){int x=0;char c=getchar();while(c<'0' || c>'9')c=getchar();while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+c-48;c=getchar();}return x;}
inline void write(int x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}
bool mbe;

int n,val,w[maxn];
vector<int> a[maxn],q[maxn];
int lsh[maxn],len;
int lsh1[maxn],len1;
struct bit{
	int f[maxn];
	void upd(int l,int r,int w){
		if(l>r)return ;
		// cout<<l<<" "<<r<<" "<<w<<"\n";
		f[l]+=w,f[r+1]-=w;
	}
	inline int que(int x){return f[x];}
	void calc(){
		for(int i=1;i<=len;i++)f[i]+=f[i-1];
	}
}t1,t2;
int suf[maxn];
int ans[maxn];
vector<int> res;
int tim[maxn];
void work(){
	n=read();
	int m=0;
	for(int i=1;i<=n;i++){
		int k=read();a[i].resize(k);
		for(int j=0;j<k;j++)a[i][j]=read();
		for(int j=0;j<k;j++)lsh1[++len1]=a[i][j];
		for(int j=1;j<k;j++)lsh[++len]=a[i][j]-a[i][j-1]+1;
		m+=k;
	}
	// assert(m<=1000000);
	lsh[++len]=1;
	val=read();for(int i=1;i<=n;i++)w[i]=read()*i;
	sort(lsh+1,lsh+len+1),len=unique(lsh+1,lsh+len+1)-lsh-1;
	sort(lsh1+1,lsh1+len1+1),len1=unique(lsh1+1,lsh1+len1+1)-lsh1-1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<a[i].size();j++)a[i][j]=lower_bound(lsh1+1,lsh1+len1+1,a[i][j])-lsh1;
		for(int j=1;j<a[i].size();j++)q[a[i][j]].pb(a[i][j-1]);
		tim[a[i][0]]++;
	}
	for(int i=1;i<=len1;i++){
		sort(q[i].begin(),q[i].end());
		suf[q[i].size()]=0;for(int j=q[i].size()-1;~j;j--)suf[j]=suf[j+1]+lsh1[q[i][j]];
		int lst=len+1;
		for(int j=0;j<q[i].size();j++){
			int t=lower_bound(lsh+1,lsh+len+1,lsh1[i]-lsh1[q[i][j]]+1)-lsh;
			// cout<<i<<" "<<j<<" "<<t<<"\n";
			t1.upd(t,lst-1,w[j+tim[i]]+((q[i].size()-j)*lsh1[i]-suf[j])*val);
			t2.upd(t,lst-1,j);
			lst=t;
		}
		t1.upd(1,lst-1,w[q[i].size()+tim[i]]);t2.upd(1,lst-1,q[i].size());
		// cout<<i<<" "<<lst<<" "<<tim[i]<<" "<<q[i].size()<<" a\n";
		// for(int j=1;j<=len;j++)cout<<j<<" "<<lsh[j]<<" "<<t1.que(j)<<" "<<t2.que(j)<<" "<<t1.que(j)+val*lsh[j]*t2.que(j)<<"\n";
	}
	t2.f[1]+=n;
	t1.calc(),t2.calc();
	// for(int j=1;j<=len;j++)cout<<j<<" "<<lsh[j]<<" "<<t1.que(j)<<" "<<t2.que(j)<<" "<<t1.que(j)+val*lsh[j]*t2.que(j)<<"\n";
	for(int i=1;i<=len;i++)ans[i]=t1.que(i)+val*lsh[i]*t2.que(i);
	int mn=ans[1];for(int i=1;i<=len;i++)mn=min(mn,ans[i]);
	for(int i=1;i<=len;i++)if(ans[i]==mn)res.pb(lsh[i]);
	// assert(mn<=inf);
	printf("%lld %lld\n",mn,res.size());
	for(int i:res)printf("%lld ",i);
	// cout<<"\n"<<lsh[2]<<" "<<ans[2]<<"\n";
}

bool med;
int T;
signed main(){
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	
	// cerr<<(&mbe-&med)/1024.0/1024.0<<"\n";
	
	T=1;
	while(T--)work();
}